package com.hailian.fintech.hlhouse_statusserver.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hailian.fintech.hlhouse_statusserver.entity.Area;
import com.hailian.fintech.hlhouse_statusserver.entity.Building;
import com.hailian.fintech.hlhouse_statusserver.service.IAreaService;
import com.hailian.fintech.hlhouse_statusserver.service.IBuildingService;
import com.hailian.fintech.hlhouse_statusserver.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hanbo
 * @since 2020-06-01
 */
@RestController
@RequestMapping("/building")
public class BuildingController {

    //注入楼盘service
    @Autowired
    private IBuildingService iBuildingService;
    //注入地区service
    @Autowired
    private IAreaService iAreaService;

    /**
     * 查询所有楼盘并且测试三级联动数据是否正确
     * @return
     */
    @RequestMapping("list")
    public ResultEntity list(){
        Wrapper wrapper = new EntityWrapper();
        List<Building> buidList = iBuildingService.selectList(wrapper);
        //关联查询三级联动省name
        for (Building buidlist:buidList){
            Area area = iAreaService.selectById(buidlist.getProvince());
            buidlist.setProvinceaddr(area.getName());
        }
        //关联查询三级联动市name
        for (Building buidlist:buidList){
            Area area = iAreaService.selectById(buidlist.getCity());
            buidlist.setCityaddr(area.getName());
        }
        //关联查询三级联动区name
        for (Building buidlist:buidList){
            Area area = iAreaService.selectById(buidlist.getCounty());
            buidlist.setAreaaddr(area.getName());
        }
        return ResultEntity.ok(buidList);

    }

}
